import uuid
from django.db import models
from projects.userprofile.models import UserProfile


class Message(models.Model):
    """
    关于消息的存贮是一道学问, 这里仅仅以最基础的发一条存储一条的方式进行设计
    """
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    from_user = models.ForeignKey(to=UserProfile, related_name="from_user",
                                  on_delete=models.DO_NOTHING, verbose_name='发送者uid')
    to_user = models.ForeignKey(to=UserProfile, related_name="to_user",
                                on_delete=models.DO_NOTHING, verbose_name='接收者uid')

    content = models.CharField(max_length=256, null=False, verbose_name='消息内容')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='消息发送时间')

    class Meta:
        ordering = ['-create_time']
        db_table = 'message'
        verbose_name = "单聊消息"
        verbose_name_plural = "单聊消息"
